package com.edushare.common.dao.academics.grades;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.edushare.common.dao.CayenneBasedDAO;
import com.edushare.common.orm.ORMInterface;
import com.edushare.common.vo.AcademicYearModel;
import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Courses;

public class GradeHistory extends CayenneBasedDAO {

	public GradeHistory(ORMInterface ormInterface) {
		super(ormInterface);
	}

	public CourseInstances getPastInstance(Courses course, int acadYear, AcademicYearModel semNum){
		List<CourseInstances> instList = course.getCourseInstances();
		for(CourseInstances cinst:instList){
			if(cinst.getSemester() == semNum && cinst.getInstanceYear() ==	acadYear)
				return cinst;
		}
		return createPastInstance(course, acadYear, semNum);
	}

	public CourseInstances createPastInstance(Courses course, int acadYear,
			AcademicYearModel semNum) {
		CourseInstances cinst = new CourseInstances();
		cinst.setCourse(course);
		cinst.setCreationTimestamp(new Date());
		cinst.setDescription("");
		cinst.setInstanceYear(acadYear);
		cinst.setSemester(semNum);
		cinst.setStatus(CourseInstances.COURSE_CLOSED);
		getDataContext().registerNewObject(cinst);
		getDataContext().commitChanges();
		return cinst;
	}

	public List<CourseInstances> getMandatoryCourses(int acadYear, AcademicYearModel semNum) {
		return new ArrayList<CourseInstances>();
	}

	public void getOptionalCourses() {

	}

}
